package deanandjames;

import deanandjames.sound.Music;
import deanandjames.ui.GamePanel;

import javax.swing.*;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;

@SuppressWarnings("serial")
public class HorizontalPlatformGame extends JFrame implements WindowListener {
	private static int DEFAULT_FPS = 30;

	public static void main(String args[]) {
		final long period = (long) 1000.0 / DEFAULT_FPS;
		new HorizontalPlatformGame(period * 1000000L);
	}

	private final Music music;
	private final GamePanel panel;

	public HorizontalPlatformGame(long period) {
		super("HorizontalPlatform");

		music = new Music();
		music.play();

		panel = new GamePanel(this, period);
		getContentPane().add(panel, "Center");
		addWindowListener(this);
		pack();
		setResizable(false);
		setVisible(true);
	}

	public void windowActivated(WindowEvent e) {
		panel.resumeGame();
	}

	public void windowClosed(WindowEvent e) {
	}

	public void windowClosing(WindowEvent e) {
		panel.stopGame();
		music.stop();
	}

	public void windowDeactivated(WindowEvent e) {
		panel.pauseGame();
	}

	public void windowDeiconified(WindowEvent e) {
		panel.resumeGame();
	}

	public void windowIconified(WindowEvent e) {
		panel.pauseGame();
	}

	public void windowOpened(WindowEvent e) {
	}
}
